<?php
	class HomeController extends Zend_Controller_Action{
		public $db;
		public $languageAdapter;

		/*初始化公共*/
		function init(){
			$this->db = Zend_Registry::get('db');
		}

		/*动作分发器*/
		public function preDispatch(){
			
			$request = $this->getRequest();
			$controller = $request->getControllerName();
			$action = $request->getActionName();
			$auth = Zend_Auth::getInstance();
			
			/*加载语言包*/
	        $languageSession = new Zend_Session_Namespace ('language');//语言命名空间
	        $lang = Zend_Registry::get('lang');
			if(isset($request->lang) && in_array($lang,Zend_Registry::get('lang'))) {
	        	$languageSession->lang = $request->lang;//设置当前语言
	        }else{
	        	$locale = new Zend_Locale();
	        	$language = strtolower($locale->findLocale());
	        	$lang = $languageSession->lang = $language;
	        }

			if(file_exists(ROOT_PATH . "/languages/{$lang}.php") && file_exists(ROOT_PATH . "/languages/{$lang}/{$controller}.php")){
				
				$this->languageAdapter = new Zend_Translate('array', ROOT_PATH . "/languages/{$lang}.php", "{$lang}");
				$this->languageAdapter->addTranslation(ROOT_PATH . "/languages/{$lang}/{$controller}.php", "{$lang}");
				Zend_Registry::set('Zend_translate',$this->languageAdapter);
			}
			

			/*判断登录*/
			if($controller == 'auth' || $controller == 'error'){

			}else{
				if($auth->hasIdentity()){
					$this->_redirect('user/login');
				}
			}

		}

		/*取得登录信息,预留*/
		public function getAuth(){
	        $data = array();
	        $auth = Zend_Auth::getInstance();
	        return $data;
    	}
	}